package outViewMonteCarlo;

import java.awt.*;
import java.util.LinkedList;

/**
 * 〈一句话功能简述>
 * 〈用蒙特卡洛的方式求 PI 的值〉
 *
 * @Author 17505
 * @Create 2021/6/8
 * @Since 1.0.0
 */
public class MonteCarloPiData {

    /**
     * 在园中的点
     */
    private Integer insideCircle = 0;
    /** 圆  */
    private Circle circle;
    /** 点  */
    private LinkedList <Point> points;

    public MonteCarloPiData(Circle circle) {
        this.circle = circle;
        points = new LinkedList <>();
    }

    public Circle getCircle() {
        return circle;
    }

    public Point getPoint(int i) {
        if (i < 0 || i >= points.size()) {
            throw new IllegalArgumentException("out of bound in getPoint");
        }
        return points.get(i);
    }

    public int getPointsNumber() {
        return points.size();
    }

    public void addPoint(Point p) {
        points.add(p);
        if (circle.contain(p)) {
            insideCircle++;
        }
    }

    public double estimatePi() {
        if (points.size() == 0) {
            return 0.0;
        }
        int circleArea = insideCircle;
        int squareArea = points.size();
        return  (double) 4 * circleArea / squareArea;
    }

}